package javase2.day06.demo08;

public class RunnableImpl implements Runnable {
    //票源
    private int ticket=100;

    //锁对象
    Object obj=new Object();
    @Override
    public void run() {
        while (true){
          payTicket();
            //跳出死循环
            if (ticket==0){
                break;
            }
        }
    }
    //锁对象是this 而如果是静态方法他的锁对象就是本类的class属性--->class文件对象（反射）
    public synchronized void payTicket(){
        if (ticket>0){
            System.out.println(Thread.currentThread().getName()+"正在卖第"+ticket+"张票");
            ticket--;
        }
    }
}
